import { CoolController, BaseController } from '@cool-midway/core';
import { Body, Inject, Post, Get, Query } from '@midwayjs/core';
import { MemberUserInfoEntity } from '../../entity/info';
import { MemberUserInfoService } from '../../service/infoMember';
import { OrderPayService } from "../../../order/service/pay";

/**
 * member模块-用户信息
 */
@CoolController({
  prefix: "/apid/member",
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: MemberUserInfoEntity,
  service: MemberUserInfoService,
  pageQueryOp: {
    keyWordLikeFields: ['username', 'nickname'],
    fieldEq: ['level', 'status'],
    where: async (ctx) => {
      return [['a.age > :age', { age: 18 }]];
    }
  }
})


export class AdminMemberUserInfoController extends BaseController {
  @Inject()
  memberUserInfoService: MemberUserInfoService;

  @Inject()
  orderPayService: OrderPayService;

  @Post('/detail', { summary: '获取用户详情' })
  async detail(@Body('id') id: number) {
    return this.ok(await this.memberUserInfoService.info(id));
  }

  @Post('/createMember', { summary: '获取用户详情' })
  async createMember(@Body() BodyData: any) {
    return this.ok(await this.memberUserInfoService.createMember(BodyData));
  }

  @Post('/updateMember', { summary: '修改用户信息' })
  async updateMember(@Body() BodyData: any) {
    return this.ok(await this.memberUserInfoService.updateMember(BodyData));
  }

  // 获取用户信息
  @Get('/getUserInfo', { summary: '获取用户信息' })
  // async getUserInfo(@Query('key') key: string) {
  async getUserInfo() {
    return this.ok(await this.memberUserInfoService.getUserInfo());
  }

  @Post('/updatePassword', { summary: '修改用户密码' })
  async updatePassword(@Body() BodyData: any) {
    return this.ok(await this.memberUserInfoService.updatePassword(BodyData));
  }

  @Post('/login', { summary: '修改用户密码' })
  async login(@Body() BodyData: any) {
    return this.ok(await this.memberUserInfoService.login(BodyData));
  }

  @Post('/baner', { summary: '获取banner' })
  async baner(@Body() BodyData: any) {
    return this.ok(await this.memberUserInfoService.baner(BodyData));
  }

  @Post('/anchorList', { summary: '获取主播' })
  async anchorList(@Body() BodyData: any) {
    return this.ok(await this.memberUserInfoService.anchorList(BodyData));
  }

  // 获取照片分类
  @Get('/dictList', { summary: '获取主播' })
  // async dictList(@Query('key') key: string) {
  async dictList(@Query('keyId') keyId: string) {
    return this.ok(await this.memberUserInfoService.dictList(keyId));
  }

  // 获取照片分页
  @Get('/photoList', { summary: '获取主播' })
  async photoList(@Query() queryData: any) {
    // async photoList() {
    return this.ok(await this.memberUserInfoService.photoList(queryData));
  }

  // 获取动态分页
  @Get('/dynamicList', { summary: '获取动态分页' })
  async dynamicList(@Query() queryData: any) {
    // async dynamicList() {
    return this.ok(await this.memberUserInfoService.dynamicList(queryData));
  }

  // 获取主播动态分页
  @Get('/anchorDynamicList', { summary: '获取主播动态分页' })
  async anchorDynamicList(@Query() queryData: any) {
    // async anchorDynamicList() {
    return this.ok(await this.memberUserInfoService.anchorDynamicList(queryData));
  }

  // 获取主播详情
  @Get('/anchorInfo', { summary: '获取主播详情' })
  async anchorInfo(@Query() queryData: any) {
    return this.ok(await this.memberUserInfoService.anchorInfo(queryData));
  }

  // 获取通知
  @Get('/inform', { summary: '获取主播详情' })
  async inform(@Query() queryData: any) {
    return this.ok(await this.memberUserInfoService.inform(queryData));
  }

  // 会员反馈
  @Post('/userfeedback', { summary: '获取主播' })
  async userfeedback(@Body() BodyData: any) {
    return this.ok(await this.memberUserInfoService.userfeedback(BodyData));
  }

  // 会员升级支付
  @Post('/upgradeMemberPay', { summary: '会员升级支付' })
  async upgradeMemberPay(@Body() BodyData: any) {
    let goodsId = Number(BodyData.id)
    let orderType = 2
    return this.ok(await this.orderPayService.aliApp(goodsId, orderType));
  }

  @Get('/orderList', { summary: '获取订单列表' })
  async orderList(@Query() BodyData: any) {
    return this.ok(await this.memberUserInfoService.orderList(BodyData));
  }
  
}
